package com.zjj.wangluo.lianxi.tcp01;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 */
public class TCPClient {

    public static void main(String[] args) {
        Socket socket = null;
        OutputStream os = null;
        PrintWriter pw = null;
        System.out.println("------------客户端-------------");
        try {
            //客户端
            socket = new Socket(InetAddress.getLocalHost(), 8888);
            //客户端 发送消息
            os = socket.getOutputStream();
            pw = new PrintWriter(os);
            pw.println("Hello , 我是客户端！");
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
